package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ImageUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.github.barteksc.pdfviewer.PDFView;

import java.io.File;

import flc.ast.R;
import flc.ast.bean.MyConvRecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class ConvRecordAdapter extends StkProviderMultiAdapter<MyConvRecordBean> {

    public ConvRecordAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(75));
        addItemProvider(new ConvRecordProvider());
    }

    private class ConvRecordProvider extends BaseItemProvider<MyConvRecordBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_conv_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyConvRecordBean bean) {
            baseViewHolder.setText(R.id.tvConvRecordItemName, bean.getName());
            baseViewHolder.setText(R.id.tvConvRecordItemDesc, bean.getDate() + "  " + bean.getSize());
            if (ImageUtils.isImage(bean.getPath())) {
                Glide.with(getContext()).load(bean.getPath())
                        .into((ImageView) baseViewHolder.getView(R.id.ivConvRecordItemImg));
                baseViewHolder.getView(R.id.ivConvRecordItemImg).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.pvConvRecordItemPdf).setVisibility(View.GONE);
            } else {
                PDFView pdfView = baseViewHolder.getView(R.id.pvConvRecordItemPdf);
                pdfView.fromFile(new File(bean.getPath())).load();
                baseViewHolder.getView(R.id.ivConvRecordItemImg).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.pvConvRecordItemPdf).setVisibility(View.VISIBLE);
            }
        }
    }
}
